<template>
  <div class="wrap">
    <div class="block">
      <el-carousel :autoplay="autoplay" indicator-position='none' height="100%">
        <el-carousel-item v-for="item in swiperPageNumber" :key="item">
          <div
            class="item"
            v-for="i in count"
            :key="i"
            :style="getStyle(i)"
          >
            <div class="details" v-if="datas[(item-1)*count+i-1]!== undefined">
              <rtmp :id="datas[(item-1)*count+i-1].id" :src="datas[(item-1)*count+i-1].url" />
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>
<script>
import rtmp from '@/components/rtmp.vue'
export default {
  name: 'showScreen',
  components: {
    rtmp
  },
  props: {
    // 总共需要展示的格子数
    sum: {
      type: Number,
      required: true
    },
    datas: {
      type: Array,
      required: true
    },
    autoplay: {
      type: Boolean,
      required: true
    }
  },
  computed: {
    swiperPageNumber () {
      return Math.ceil(this.datas.length / this.count)
    },
    styles () {
      const { sum } = this
      return {
        width: `${(1 / Math.sqrt(sum)) * 100}%`,
        height: `${(1 / Math.sqrt(sum)) * 100}%`
      }
    },
    bigStyles () {
      const { big, sum } = this
      return {
        width: `${((big / Math.sqrt(sum)) * 100 - 0.15).toFixed(1)}%`,
        height: `${((big / Math.sqrt(sum)) * 100 - 0.15).toFixed(1)}%`
      }
    },
    big () {
      let big = Math.sqrt(this.sum) - 1
      if (big < 1) big = 1
      if (big > 3) big = 3
      return big
    },
    count () {
      return this.sum - this.big ** 2 + 1
    }
  },
  methods: {
    getStyle (i) {
      if (i === 1) {
        return this.bigStyles
      }
      return this.styles
    }
  }
}
</script>
<style lang="scss" scoped>
.wrap {
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 1600px;
  height: 900px;
  z-index: 10;
  /deep/ .block{
    height: 900px;
    .el-carousel{
      height: 900px;
    }
  }
  .item {
    border-radius: 4px;
    background: #000;
    float: left;
    border: 1px solid #fff;
    box-sizing: border-box;
    position: relative;

    p{
      position: absolute;
      top: 0;
      left: 10px;
    }
  }
}
</style>
